package h0902;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 验证是否是回文串
 * @date 2024/9/2 10:21
 */
public class JudgePalindrome {
    public static void main(String[] args) {
        String s = "0P";
        System.out.println(isPalindrome(s));
    }

    public static boolean isPalindrome(String s) {
        if (s.isEmpty()) return true;
        int left = 0;
        int right = s.length() - 1;
        while (left <= right) {
            char b = s.charAt(left);
            char c = s.charAt(right);
            if (!Character.isLetterOrDigit(b)){
                left++;
                continue;
            }
            if (!Character.isLetterOrDigit(c)){
                right--;
                continue;
            }
            if (Character.isLetter(b)){
                b=Character.toLowerCase(b);
            }
            if (Character.isLetter(c)){
                c=Character.toLowerCase(c);
            }
            if (b!=c) return false;
            left++;
            right--;
        }
        return true;
    }
}
